
// 引入埋点SDK
import dhtrack from '@/util/dhtrack_wx'
export default {
    data() {
        return {
            
        }
    },
    methods: {
		/**
		 * 埋点-启动事件（onLaunch上报openApp）
		 * 获取uid，登录完成后会将uid(encryptPhone用户唯一标识)存储到本地
		 */
		getOpenApp(){
			// 埋点首次启动加载-开始
			// 获取uid，登录完成后会将uid(encryptPhone用户唯一标识)存储到本地
			let dh_track_uid = wx.getStorageSync('dh_track_uid')
			let uid = ''
			if(dh_track_uid) {
				uid = dh_track_uid;
			} else {
				let lifeData = wx.getStorageSync('lifeData')
				if(lifeData?.vuex_userInfo?.encryptPhone){
					// encryptPhone登录后返回的加密手机号
					let encryptPhone = 'encryptPhone'
					uid = encryptPhone
					wx.setStorageSync('dh_track_uid',encryptPhone)
				}
			}
			// 获取uid并启动app
			dhtrack.setParams({ uid }).trackEvent('openApp',{})
			// 埋点首次启动加载-结束
		},
		
		/**
		 * 埋点-卸载事件（返回上一页、非uni.navigateTo跳转）
		 */
		unloadEvent(){
			if(!dhtrack.baseConfig.switch) return
			let entryTime = getApp().globalData.entryTime
			let leaveTime = new Date().getTime()
			dhtrack.trackEvent('viewPage',{
				// 页面名称
				title: dhtrack.paramFnc.title(),
				// 当前页面路径
				url: dhtrack.paramFnc.url(),
				// 原路径-要返回的页面路径
				oldPage: dhtrack.paramFnc.referrer(),
				// 页面停留时长
				duringTime: leaveTime - entryTime,
			})
			// 更新最后离开时间
			getApp().globalData.entryTime = leaveTime
		}
    }
}